package com.example.hp.yuejian5.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hp.yuejian5.R;
import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;


import com.example.hp.yuejian5.bean.CompetitionBean;
import com.example.hp.yuejian5.model.Competition_DetailModel;
import com.squareup.picasso.Picasso;

import static com.example.hp.yuejian5.other.url.IMAGES;

public class Competition_DetailActivity extends AppCompatActivity{
    private String i_id, u_id;
    private Context context;
    private FragmentTransaction fragmentTransaction;
    private FragmentManager fragmentManager;
    private RetrofitListener<CompetitionBean> listener;

    private ImageView competition_detail_pic;
    private Toolbar toolbar;
    private TextView toolbartitle;
    private int flagattention;
    private SharedPreferences sp;
    private TextView competition_detail_name,competition_detail_id,competition_detail_detail,competition_detail_starttime,
            competition_detail_endtime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_competition_detail);
        setSupportActionBar(toolbar);
        Intent intent = getIntent();
        i_id = (String) intent.getStringExtra("com_id");
        sp = getSharedPreferences("user_id", Context.MODE_PRIVATE);
        u_id = sp.getString("userid", null);
        initView();

        listener = new RetrofitListener<CompetitionBean>() {
            @Override
            public void onSuccess(CompetitionBean competitionBean, int flag) {
                competition_detail_name.setText(competitionBean.getCompetition_name());
                competition_detail_id.setText(competitionBean.getCompetition_id());
                competition_detail_detail.setText(competitionBean.getCompetition_detail());
                competition_detail_starttime.setText(competitionBean.getCompetition_starttime());
                competition_detail_endtime.setText(competitionBean.getCompetition_endtime());


                Picasso.with(context).load(IMAGES + competitionBean.getCompetition_pic()).into(competition_detail_pic);
            }

            @Override
            public void onFail() {

            }
        };


        competitionDetail();

    }

    private void initView() {
        competition_detail_pic = findViewById(R.id.competition_detail_pic);
        competition_detail_name = findViewById(R.id.competition_detail_name);
        competition_detail_id = findViewById(R.id.competition_detail_id);
        competition_detail_detail = findViewById(R.id.competition_detail_detail);
        competition_detail_starttime = findViewById(R.id.competition_detail_starttime);
        competition_detail_endtime = findViewById(R.id.competition_detail_endtime);

        toolbar = findViewById(R.id.competition_detail_toolbar);
        toolbartitle = findViewById(R.id.competition_detail_toolbar_text);
    }


    private void competitionDetail() {
        Competition_DetailModel club_detailModel = new Competition_DetailModel();
        club_detailModel.competitionDetail(i_id, listener);
    }


}
